package com.liull.spring_anno.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @Author: liull
 * @Description:
 * @Date: Created in 21:38 2020/4/9
 * @Modified By:
 */
@Aspect
@Component
public class LogAspects {
    public LogAspects() {
    }

    @Pointcut("execution(* com.liull.spring_anno.aop..*.div(..))")
    public void businessService() {
    }

    @Before(value = "businessService()")
    public void before(JoinPoint point) {
        Object[] args = point.getArgs();
        String name = point.getSignature().getName();
        System.out.println("point.getSignature().getName()" + name);
        for (Object o : args) {
            System.out.println("除法运行前，参数是：" + o);
        }
    }

    @After(value = "businessService()")
    public void after(JoinPoint point) {
        System.out.println("除法运行结束。");
    }

    @AfterReturning(value = "businessService()", returning = "result")
    public void afterReturning(Object result) {
        System.out.println("除法运行正常返回结果是：" + result);
    }

    @AfterThrowing(value = "businessService()", throwing = "throwable")
    public void afterThrowing(Exception throwable) {
        System.out.println("除法异常返回，异常信息是：" + throwable.getMessage());
    }

    @Around(value = "businessService()")
    public void around(ProceedingJoinPoint joinPoint) {
        try {
            joinPoint.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
    }
}
